package cn.tedu.charging.order.config;

import com.xxl.job.core.executor.impl.XxlJobSpringExecutor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
@Slf4j
public class XxlJobConfig {
    @Value("${xxl.job.admin.addresses}")
    private String adminAddresses;

    // xxl-job访问令牌
    @Value("${xxl.job.accessToken}")
    private String accessToken;

    // xxl-job执行器应用名称
    @Value("${xxl.job.executor.appname}")
    private String appname;

    // xxl-job执行器地址 和ip和port关系 ip 127.0.0.1 port 19999 address 127.0.0.1:19999
    @Value("${xxl.job.executor.address}")
    private String address;

    // xxl-job执行器IP
    @Value("${xxl.job.executor.ip}")
    private String ip;

    // xxl-job执行器端口号
    @Value("${xxl.job.executor.port}")
    private int port;

    // xxl-job执行器日志路径
    @Value("${xxl.job.executor.logpath}")
    private String logPath;

    // xxl-job执行器日志保留天数
    @Value("${xxl.job.executor.logretentiondays}")
    private int logRetentionDays;
    //只需要一个xxl-job提供的类型 创建为容器bean
    //@Bean
    public XxlJobSpringExecutor xxlJobInit(){
        XxlJobSpringExecutor executor = new XxlJobSpringExecutor();
        //属性初始化 否则executor无法和admin调度中心通信
        //填写 连接调度中心地址localhost:8080/xx-job-admin
        executor.setAdminAddresses(adminAddresses);
        executor.setAccessToken(accessToken);
        //执行器在 初始化成实例之后,就会和8080调度中心通信
        executor.setAppname(appname);
        //执行器 名称
        executor.setAddress(address);
        //执行器 所在地址 ip port
        executor.setIp(ip);
        executor.setPort(port);//19999
        executor.setLogPath(logPath);
        executor.setLogRetentionDays(logRetentionDays);
        return executor;
    }
}
